package com.gxa.modules.pc.sys.usermanager.controller;

import com.gxa.common.utils.Result;
import com.gxa.modules.pc.sys.usermanager.dto.RolePcDto;
import com.gxa.modules.pc.sys.usermanager.dto.RoleSearchDto;
import com.gxa.modules.pc.sys.usermanager.service.RolePcService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName RolePcController
 * @Description
 * @Author Mr.YUAN
 * @Date 2022/11/17 20:28
 */
@Api(tags = "角色管理")
@RestController
@RequestMapping("/role")
public class RolePcController {

    @Autowired
    private RolePcService rolePcService;

//    @RequiresPermissions("role:list")
    @ApiOperation(value = "查询所有角色",response = RoleSearchDto.class)
    @PostMapping("/list")
    public Result list(@RequestBody RoleSearchDto roleSearchDto) {
        Result result = rolePcService.queryAll(roleSearchDto);
        return result;
    }

    @ApiOperation(value = "新增角色",response = RolePcDto.class)
//    @ApiImplicitParams({
//            @ApiImplicitParam(paramType = "body",name = "rolePcDto",value = "角色",dataType = "json"),
//            @ApiImplicitParam(paramType = "query",name = "menuList",value = "权限",dataType = "list")
//    })
    @PostMapping("/add")
    public Result add(@RequestBody RolePcDto rolePcDto) {
        rolePcService.addRole(rolePcDto);
        return new Result().ok();
    }

    @ApiOperation("修改角色")
    @PutMapping("/update")
    public Result update(@RequestBody RolePcDto rolePcDto) {
        rolePcService.update(rolePcDto);
        return new Result().ok();
    }

//    @ApiOperation("删除角色")
//    @PostMapping("/delete")
//    public Result delete(Integer id) {
//        rolePcService.delete(id);
//        return new Result().ok();
//    }
    @ApiOperation("删除角色")
    @PostMapping("/delete")
        public Result delete(@RequestBody List<Integer> ids) {
        rolePcService.delete(ids);
        return new Result().ok();
    }

    @ApiOperation("通过角色的id查单条数据")
    @GetMapping("/getone")
    public Result getOne(Integer id) {
        Result result = rolePcService.selectOne(id);
        return result;
    }

}